<template>
	<view>

		<view class="herProject-container">
			<view class="avator-container">
				<view class="publisher-avator">
					<view class="cu-avatar lg round" :style="{ 'background-image': `url(${avatar})` }"></view>
					<span>{{ name }}</span>
				</view>
			</view>
			<view class="projectItem-container">
				<view class="intro">TA发布的项目</view>
				<view class="taskList">
					<view class="task-item" v-for="item in projectList" :key="item.id" @tap="gotoDetail(item.id)">
						<view class="item-top">
							<view class="item-title">{{ item.name }}</view>
							<view class="item-money">{{ item.price }}<span>元</span></view>
						</view>
						<view class="item-content">

							<!-- 富文本 -->
							<!-- <rich-text :nodes="item.content" space="nbsp"></rich-text> -->
						</view>
						<view class="tagsList">
							<view class="tags" v-for="(keyword, kIndex) in item.keywords.split(',')" :key="kIndex"
								v-if="item.keywords !== ''">{{ keyword }}</view>
						</view>
						<view class="publisher-container">
							<view class="publisher-avator">
								<view class="cu-avatar round" :style="{ 'background-image': `url(${item.create_user.avatar})` }">
								</view>
								<span>{{ item.create_user.username }}</span>
							</view>
							<view class="publisher-location">
								<text>{{ item.city }}</text>
							</view>
						</view>
						<view class="edit-container" v-if="false">
							<view class="edit" @tap="$openrul(`/subpackage/editPage/editPage?id=${item.id}`)">
								编辑
							</view>
							<view class="delete" @tap="DeleteMotal(item.id)">
								删除
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
export default {
	data() {
		return {
			projectList: [],
			limit: 1000,
			modalName: null,
			name: '',
			userid: '',
			avatar: '',
		};
	},
	onLoad(options) {
		console.log('%c [ options ]-66', 'font-size:13px; background:pink; color:#bf2c9f;', options)
		if (options.userid) {
			console.log('有了')
			this.name = options.name
			this.userid = options.userid
			this.avatar = options.avatar
		}
	},
	onShow() {
		this.getProjectList()
	},
	methods: {
		gotoDetail(id) {

			uni.navigateTo({
				url: `/subpackage/projectDetail/projectDetail?param1=${id}`
			})
		},
		DeleteMotal(delId) {
			uni.showModal({
				title: '⚠️警告',
				content: '是否删除该项目？',
				showCancel: true, // 是否显示取消按钮
				cancelText: '取消', // 取消按钮的文字
				cancelColor: '#000000', // 取消按钮的文字颜色
				confirmText: '确认', // 确认按钮的文字
				confirmColor: '#3CC51F', // 确认按钮的文字颜色
				success: (res) => {
					if (res.confirm) {
						// 用户点击了确认按钮
						this.deleteProject(delId)

					}
				},
			});
		},

		async getProjectList(isHis) {

			let userID = JSON.parse(uni.getStorageSync('vuexvuex'))
			var parsedData = JSON.parse(userID.value);

			var create_user_id = parsedData.userinfo.user_id;
			let res = await this.$myHttp.post({
				url: this.$myHttp.urlMap.getProjectList,
				data: {
					isHis: isHis,
					page: 1,
					create_user_id: this.userid,
					limit: this.limit,
				}
			})

			// 使用 Set 来存储已经存在的数据
			let existingData = new Set(this.projectList.map(item => item.id));

			// 过滤掉已经存在的数据
			let newData = res.data.data.filter(item => !existingData.has(item.id));

			// 将新数据添加到项目列表中
			this.projectList = this.projectList.concat(newData);



			this.projectListTotal = res.data.total






		},
		async deleteProject(delId) {

			let res = await this.$myHttp.post({
				url: this.$myHttp.urlMap.deleteProject,
				data: {
					id: delId
				}
			})

			console.log('res: ', res)
			if (res.code == 1) {
				uni.showToast({
					title: '删除成功',
					icon: 'success',
				});
				this.getProjectList()
				uni.reLaunch({
					url: '/subpackage/myProjects/myProjects' // 重新打开的页面路径
				});
			} else {
				uni.showToast({
					title: '删除失败',
					icon: 'none',
				});
			}

		},
	}
}
</script>

<style lang="scss" scoped>
.edit-container {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-top: 20rpx;
	font-size: 12px;
	color: #A8A8A8;

	.edit {}

	.delete {}
}

.no-more {
	color: #999;
}

.cutpage-container {
	padding: 10px;
	color: #026aef;
	display: flex;
	align-items: center;
	justify-content: center;
}

.sendBtn-contaienr {
	// 居中
	position: fixed;
	bottom: 15px;
	right: 130px;
	margin-right: 20rpx;
	margin-bottom: 20rpx;

	image {
		width: 200rpx;
		height: 200rpx;
	}
}

.taskList {
	background-color: #F8F8F8;
	padding: 9px;

	.task-item {
		background-color: #fff;
		margin-bottom: 18rpx;
		padding: 10px;
		border-radius: 10rpx;

		.publisher-container {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 20rpx;

			.publisher-avator {
				display: flex;
				justify-content: flex-start;
				align-items: center;

				span {
					margin-left: 10rpx;
				}
			}

			.publisher-location {
				display: flex;
				justify-content: flex-end;
				align-items: center;

				text {
					font-size: 12px;
					color: #A8A8A8;
				}
			}
		}

		.item-top {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.item-title {
				font-size: 16px;
				font-weight: bold;
			}

			.item-money {
				font-size: 16px;
				color: #0074D6;
				font-weight: bold;
				background-color: #fff;

				span {
					font-size: 12px;
					margin-left: 5rpx;
					font-weight: normal;
				}
			}
		}

		.item-content {
			margin-top: 20rpx;
			margin-bottom: 20rpx;
		}

		.tagsList {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			font-size: 12px;

			.tags {
				color: #A8A8A8;
				background-color: #EDEDED;
				padding: 2px 5px;
				border-radius: 10rpx;
				margin-right: 10px;
			}
		}
	}
}

.item-content {
	margin-top: 20rpx;
	margin-bottom: 20rpx;
}

.project-item {
	margin-top: 20rpx;
	padding-bottom: 30rpx;
	border-bottom: 1px solid #EDEDED;
}

.project-top {
	margin-bottom: 20rpx;
	display: flex;
	font-size: 18px;
	justify-content: space-between;
	align-items: center;

	span {
		font-size: 12px;
		font-weight: normal;
		margin-left: 5rpx;
	}
}

.tagsList {
	display: flex;
	justify-content: flex-start;
	align-items: center;
	font-size: 12px;

	.tags {
		color: #A8A8A8;
		background-color: #EDEDED;
		padding: 2px 5px;
		border-radius: 10rpx;
		margin-right: 10px;
	}
}

.projectItem-container {
	padding: 30rpx;

	.intro {
		font-size: 18px;
		font-weight: bold;
		margin-bottom: 20rpx;
	}
}

.publisher-avator span {
	margin-left: 30rpx;
	font-size: 18px;
}

.herProject-container {}

.avator-container {
	color: #fff;
	padding: 40rpx;
	height: 200rpx;
	background-color: #4D4343;
	display: flex;
	align-items: center;
}
</style>
